<?php include_once("common/init.php");?>
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>用户注册页面</title>
  <link rel="stylesheet" href="./Public/css/login.css">
</head>
<body>
	<div id="root" style="background:url(./Public/images/bg.jpeg) center/cover no-repeat;">
		<div class="content">
			<div class="login-logo" style="font-size: 35px; font-weight: bold;">
				<a href="index.php">校园闲置物品交易系统</a>
			</div>
			<div class="login-desc"></div>
			<div class="login-box">
				<div class="tit">用户注册</div>
			<div>
				<form method="post" action="?" name="form1" id="form1"  onSubmit="return check();">
					<div class="input-box">
						<input class="ant-input" type="text" name="account" placeholder="用户名">
					</div>
					<div class="input-box">
						<input class="ant-input" type="password" name="password" placeholder="密码">
					</div>
					<div class="input-box">
						<input class="ant-input" type="password" name="password1" placeholder="重复密码">
					</div>
					<div class="input-box">
						<input class="ant-input" type="text" name="nickname" placeholder="姓名">
					</div>
					<div class="input-box">
						<input type="radio" style="width:20px;" name="sex" id="select1" value="男" checked>男
						<input type="radio" style="width:20px;" name="sex" id="select1" value="女">女
					</div>
					<div class="input-box">
						<input class="ant-input" type="text" name="email" placeholder="email">
					</div>
					<div class="input-box">
						<input class="ant-input" type="text" name="tel" placeholder="手机">
					</div>
					<div class="input-box">
						<button style="width:200px" type="submit"  class="login-bt ant-btn">
							<span>注 册</span>
						</button>
						<a class="fr reg-bt" href="login.php" rel="nofollow" style="color:white;">已有账户？ 去登录</a>
					</div>
				</form>
			</div>
		</div>
	</div>
</div>
 
</body>
</html>
<script type="text/javascript"> 
function check(){
	if(document.form1.account.value==""){
		alert("请输入用户名");
		document.form1.account.focus();
		return false;
	}
	var account1=document.form1.account.value.trim();
	if(account1==null || account1=='' || account1==undefined){
		alert("用户名不能有空格");
		document.form1.account.focus();
		return false;
	}
	if(document.form1.account.value==""){
		alert("请输入用户名");
		document.form1.account.focus();
		return false;
	}
	
	if(document.form1.password.value==""){
		alert("请输入密码");
		document.form1.password.focus();
		return false;
	}
	var upwd1=document.form1.password.value;
	//规定密码格式，最短6，最长16，由数字、大写字母、小写字母及!@#$%^&*? 字符组成
	var a=/^.*(?=.{6,16})(?=.*\d)(?=.*[A-Z])(?=.*[a-z])(?=.*[!@#$%^&*? ]).*$/;
	if(!(a.test(upwd1))){
	    alert("密码格式错误！格式应包含：数字、大小写字母及特殊符号，且6-16位。");
	    document.form1.password.focus();
	    return false;
	}
	if(document.form1.password1.value==""){
		alert("请输入确认密码");
		document.form1.password1.focus();
		return false;
	}
	if(document.form1.password.value!=document.form1.password1.value){
		alert("两次输入密码不一致");
		document.form1.password1.focus();
		return false;
	}
	if(document.form1.nickname.value==""){
		alert("姓名为必填");
		document.form1.nickname.focus();
		return false;
	}
	var email = document.form1.email.value;
	var emailreg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/; 
	if(!emailreg.test(email)){
		document.form1.email.focus();
		alert("邮箱不符合规则");
		return false;
	}
	if(document.form1.tel.value==""){
		alert("手机为必填");
		document.form1.tel.focus();
		return false;
	}
	var mobile=document.form1.tel.value;
		if(mobile.length==0) 
       { 
          alert('请输入手机号码！'); 
          document.form1.tel.focus(); 
          return false; 
       }
       var myreg = /^1[34578]\d{9}$/; 
       if(!myreg.test(mobile)) 
       { 
           alert('请输入有效的手机号码！'); 
           document.form1.tel.focus(); 
           return false; 
       }
}
</script>
<?php 
	if ($_POST){
		$row = db_get_row("select * from user where account='". $_POST["account"] ."'");
		if ($row["id"]) {
			goBakMsg("用户名已存在");
			die;
		}
		$row1 = db_get_row("select * from user where tel='". $_POST["tel"] ."'");
		if ($row1["id"]) {
			goBakMsg("手机号已存在");
			die;
		}
		$row2 = db_get_row("select * from user where email='". $_POST["email"] ."'");
		if ($row2["id"]) {
			goBakMsg("email已存在");
			die;
		}
		$data = array();
		$data["account"] = "'". $_POST["account"] ."'";
		$data["nickname"] = "'". $_POST["nickname"] ."'";
		$data["email"] = "'". $_POST["email"] ."'";
		$data["sex"] = "'". $_POST["sex"] ."'";
		$data["tel"] = "'". $_POST["tel"] ."'";
		$data["password"] = "'".$_POST["password"] ."'";
		db_add("user", $data);
		urlMsg("注册成功", "./login.php");
		die;
	}
?>